import java.awt.Color;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;

public class GreekFish extends Fish
{

    private int level, id;
    private double exp, totalExp;
    private int strength, speed;
    private boolean isInvisible;
    private int levelFactor;
    private String name;

    public GreekFish(Environment env, Location loc)
    {
        super(env, loc);
        initializeGreekFish();
    }

    public GreekFish(Environment env, Location loc, Direction dir)
    {
        super(env, loc, dir);
        initializeGreekFish();
    }

    public GreekFish(Environment env, Location loc, Direction dir, Color col)
    {
        super(env, loc, dir, col);
        initializeGreekFish();
    }

    public void initializeGreekFish()
    {
        level = 1;
        levelFactor = 1;
        exp = 0;
        totalExp = 0;
        strength = 1;
        speed = 1;
        id = this.id();
        initializeGreekFishName();
    }
    
    public void initializeGreekFishName()
    {
        if(id == 4) { name = "Seti";}
        else if(id == 5) { name = "Lee";} 
        else if(id == 6) { name = "Costas";} 
        else if(id == 7) { name = "Abdel-Rahman";} 
        else if(id == 8) { name = "Meritt";} 
        else { name = "GreekFish" + id(); }
    }
    
    public String ident()
    {
        return name;
    } 
    
    public int level()
    {
        return level;
    }  
    
    public void checkLevel()
    {
        if(exp == (6 + 2 * levelFactor))
        {
            level++; 
            exp = 0;
            if(level == 4)
                speed++;
            else if(level == 8)
                speed++; 
            else if(level == 12)
                speed++;
            levelFactor++;
        }
    }

    public void addExp(Fish deadFish)
    {  
        if(deadFish instanceof Fish) { exp += 2; }    
        // if(deadFish instanceof NoobFish) { exp += 1; }
        // else if(deadFish instanceof StoneFish) { exp += 1; }          
        else if(deadFish instanceof InfertileFish) { exp += 1; }
        else if(deadFish instanceof GreekFish) { exp += 4; }
        totalExp += exp;
        checkLevel();
    }   

    public void killFish()
    {
        // modify algorithm so 
        Fish tempFish;
        Location inFront = environment().getNeighbor(location(), direction());
        if(!(environment().isEmpty(inFront)) && environment().isValid(inFront))
        {
            tempFish = (Fish)environment().objectAt(inFront);
            if(!(tempFish.level() > this.level() + strength))
            {
                ((Fish)environment().objectAt(inFront)).die();
                addExp(tempFish);
                System.out.println(this.ident() + " ate " + tempFish.ident() + "   " + this.ident() + " lv: " + level + " exp: " + totalExp);
            }
        }
    }
    
    public void dissapear()
    {
        environment().remove(this);
        isInvisible = true;
    }
    
    public void reappear()
    {
        environment().add(this);
        isInvisible = false;
    }
    
    /* breeding disabled - largely because young
     * Fish would be at a severe disadvantage to higher level Fish
     */
    public void act()
    {
        // Make sure fish is alive and well in the environment -- fish
        // that have been removed from the environment shouldn't act.
        if ( !(isInEnv()) && !(isInvisible))
            return;

        for(int i = 0; i < speed; i++)
        {
            move();
            killFish();
        }
    }

}